package web;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Date;

@WebServlet("/ServletContextDemo4")
public class ServletContextDemo4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = request.getServletContext();
        //取数据  根据key来获取value值  (String s)
        String name =  (String)context.getAttribute("name");
        String key =  (String)context.getAttribute("key");
        response.getWriter().write(new Date().toString()+"\n");
        response.getWriter().write("key:"+key);
        response.getWriter().write("name:"+name);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().write(new Date().toString());
    }
}
